package com.linkwedo.saas.support;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.Dispatcher;

import com.opensymphony.xwork2.inject.Container;

/**
 * 
 * @author rabbit
 *
 */
public class ContextUtils {
	private ContextUtils() {
		throw new AssertionError();
	}
	
	public static String getContext() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String contextPath = request.getContextPath();
		if (contextPath.length() > 0) {
			contextPath = contextPath.substring(1, contextPath.length());
		}
		return contextPath;
	}
	
	public static String getActionExtention() {
		Container con = Dispatcher.getInstance().getConfigurationManager().getConfiguration().getContainer();  
		String s = con.getInstance(String.class, "struts.action.extension"); 
		return s;
	}
	
	public static String getHostName() {
		HttpServletRequest request = ServletActionContext.getRequest();
		return request.getServerName();
	}
	public static String getHostPort() {
		HttpServletRequest request = ServletActionContext.getRequest();
		return request.getServerPort() + "";
	}
	public static String getHostURL() {
		return getHostName() + ":" + getHostPort();
	}
}
